package com.atwbj.langchain4jbeta3learndemo.config;

import dev.langchain4j.model.chat.listener.ChatModelErrorContext;
import dev.langchain4j.model.chat.listener.ChatModelListener;
import dev.langchain4j.model.chat.listener.ChatModelRequestContext;
import dev.langchain4j.model.chat.listener.ChatModelResponseContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class ListenerConfig {
   @Bean
   ChatModelListener chatModelListener() {
      return new ChatModelListener() {

         private static final Logger log = LoggerFactory.getLogger(ChatModelListener.class);

         @Override
         public void onRequest(ChatModelRequestContext requestContext) {
            log.info("监听器----onRequest");
            log.info("onRequest(): {}", requestContext.chatRequest());
         }

         @Override
         public void onResponse(ChatModelResponseContext responseContext) {
            log.info("onResponse(): {}", responseContext.chatResponse());
         }

         @Override
         public void onError(ChatModelErrorContext errorContext) {
            log.info("onError(): {}", errorContext.error().getMessage());
         }
      };
   }
}
